#!/usr/bin/env python
""" Utility box to use with intelhex unit."""
__author__      = "Michael J. Hohmann"
__copyright__   = "Copyright 2017, Linde Material Handling GmbH"
__versio__      = "0.0.1"
__email__       = "michael.hohmann@lind-mh.de"
__status__      = "Prototype"
__date__        = "2017-02-20"

def put_u32(ihex, adr, value):
    ihex[adr+0]=(value>>0) &0xFF
    ihex[adr+1]=(value>>8) &0xFF
    ihex[adr+2]=(value>>16)&0xFF
    ihex[adr+3]=(value>>24)&0xFF
    
def get_u32(ihex, adr):
    value=0
    value|=ihex[adr+3]
    value<<=8
    value|=ihex[adr+2]
    value<<=8
    value|=ihex[adr+1]
    value<<=8
    value|=ihex[adr+0]    
    return value

def last_address(ihex):
    segments=ihex.segments()
    return segments[-1][1]
    
def first_address(ihex):
    segments=ihex.segments()
    return segments[0][0]
    
